package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.ApplyFriendEntity;
import io.renren.modules.generator.service.ApplyFriendService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author jianzhen
 * @email sunlightcs@gmail.com
 * @date 2022-04-10 11:24:32
 */
@RestController
@RequestMapping("generator/applyfriend")
@Transactional
public class ApplyFriendController {
    @Autowired
    private ApplyFriendService applyFriendService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = applyFriendService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{applyId}")
    public R info(@PathVariable("applyId") Long applyId) {
        ApplyFriendEntity applyFriend = applyFriendService.getById(applyId);

        return R.ok().put("applyFriend", applyFriend);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ApplyFriendEntity applyFriend) {
        applyFriendService.save(applyFriend);

        return R.ok();
    }


    /**
     * 通过好友申请
     *
     * @param applyId
     * @return
     */
    @RequestMapping("/passFriend/{applyId}")
    public R passFriend(@PathVariable("applyId") Long applyId) {
        applyFriendService.passFriend(applyId);

        return R.ok();
    }

    /**
     * 拒绝好友申请
     *
     * @param applyId
     * @return
     */
    @RequestMapping("/refuseFriend/{applyId}")
    public R refuseFriend(@PathVariable("applyId") Long applyId) {
        applyFriendService.refuseFriend(applyId);

        return R.ok();
    }

    /**
     * 发送好友申请
     *
     * @param friendId
     * @return
     */
    @RequestMapping("/addFriend/{friendId}")
    public R addFriend(@PathVariable("friendId") Long friendId) {
        applyFriendService.addFriend(friendId);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ApplyFriendEntity applyFriend) {
        applyFriendService.updateById(applyFriend);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] applyIds) {
        applyFriendService.removeByIds(Arrays.asList(applyIds));

        return R.ok();
    }


}
